package com.innovatio.validator.handlers;

import com.innovatio.validator.annotations.ValidateDate;
import com.innovatio.validator.ValidationErrors;
import com.innovatio.validator.Validable;
import com.innovatio.validator.exceptions.ValidatorException;
import com.innovatio.utils.general.CommonsUtils;

import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormat;

/**
 * This code is property of Innovatio Software Solutions, Inc.
 * User: Edxe
 * Date: Jul 1, 2009
 * Time: 1:36:14 AM
 */
public class ValidateDateHandler implements ValidationHandler<ValidateDate> {

    public ValidationErrors.Error validate(ValidateDate annotation, Validable container, String fieldName, String value) throws ValidatorException {

        if (!CommonsUtils.isValidDate(value, annotation.format()))
            return new ValidationErrors.Error(fieldName, annotation.i18nBundleKey());

        return null;
    }

}
